﻿using ChuanYe.CountyFireManagement.EF.MySQL.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChuanYe.CountyFireManagement.BLL
{
    public class FireLocationRecordBLL
    {
        #region 构造单例
        private FireLocationRecordBLL() { }
        private static FireLocationRecordBLL _instance;
        public static FireLocationRecordBLL Instance
        {
            get
            {
                return _instance ?? (_instance = new FireLocationRecordBLL());
            }
        }
        #endregion

        public int Add(List<Firelocationrecord> infos)
        {
            using (CountyFireManagementContext ef = new CountyFireManagementContext())
            {
                foreach (var item in infos)
                {
                    ef.Firelocationrecord.Add(item);
                    ef.Entry<Firelocationrecord>(item).State = EntityState.Added;
                }
                ef.SaveChanges();
                return 1;
            }
        }

        public List<Firelocationrecord> Get(int fireId,int recordType)
        {
            using (CountyFireManagementContext ef = new CountyFireManagementContext())
            {
                return ef.Firelocationrecord.Where(p=>p.FireId==fireId && p.RecordType==recordType).OrderBy(o=>o.TransDatetime).ToList();
            }
        }

    }
}
